package com.ady.collect;

import com.ady.util.FrameUtil;
import com.ady.util.IDUtil;
import com.ady.util.StringUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.List;
import java.util.Map;

@NoArgsConstructor
@Accessors
@Data
@Builder
@AllArgsConstructor
public class FilmModel {
    private String id;
    private String title;
    private String ftpUrl;
    private Map<String, Object> extMap;
    private List<FilmModel> list;


    public FilmModel putExtMap(String key, Object value) {
        if (extMap == null) {
            extMap = FrameUtil.newHashMap();
        }
        extMap.put(key, value);
        return this;
    }

    public FilmModel addItem(FilmModel fm) {
        if (this.list == null) {
            this.list = FrameUtil.newArrayList();
        }
        this.list.add(fm);
        return this;
    }

    public FilmModel initExtMap() {
        if (StringUtil.isEmpty(this.getId())) {
            this.setId(IDUtil.getId());
        }
        if (StringUtil.isNotEmpty(ftpUrl)) {
            String thunder = LinkUtil.getThunder(ftpUrl);
            String flashget = LinkUtil.getFlashget(ftpUrl);
            String qqdl = LinkUtil.getQqdl(ftpUrl);
            this.putExtMap("thunder", thunder);
            this.putExtMap("flashget", flashget);
            this.putExtMap("qqdl", qqdl);
        }
        return this;
    }

    public static void main(String[] args) {
        String s = "<div class=\"film_item\">" +
                "            <a class=\"film_link\" target=\"film_detail\" title=\"${item.title}\" href=\"<@ms_lib.action url='/rs/film/detail/${item.id?string(\"0\")}'/>\" class=\"figure film_a\">" +
                "                <span class=\"title\">${item.title}</span>" +
                "                <span class=\"film_pub_time\">${item.extData.pub_time}</span>" +
                "            </a>" +
                "        </div>";
    }
}
